package cn.gem.rainbow.cfg.web.listener;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * SpringBoot系列教程web篇Listener四种注册姿势
 * https://www.cnblogs.com/yihuihui/p/12034522.html
 */
@Configuration
public class WebListenerConfig {

    /**
     * 通过java config来主动将一个普通的Listener对象，
     * 塞入ServletListenerRegistrationBean对象，创建为spring的bean对象
     * @return
     */
    @Bean
    public ServletListenerRegistrationBean configContextListener() {
        ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean();
        bean.setListener(new CustomContextListener());
        return bean;
    }
}
